package com.chenfan.ccp.plug.mq.config;

import com.chenfan.ccp.plug.mq.annotation.MqMessageListener;
import com.chenfan.ccp.util.tool.JsonUtil;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.type.AnnotationMetadata;


public class MqRegisterConfigure implements ImportBeanDefinitionRegistrar {

    public static final String LINK = ",";
    /**
     * 增加随机数防止别名重复
     */
    private static final String MQ_REGISTER_PREFIX = "mqRegister" + System.nanoTime() + ":";

    public static String getMqAliasBeanName() {
        return MQ_REGISTER_PREFIX;
    }

    @Override
    public void registerBeanDefinitions(AnnotationMetadata metadata, BeanDefinitionRegistry registry) {
        registry.registerAlias(MQ_REGISTER_PREFIX, metadata.getClassName() + LINK + JsonUtil.obj2String(metadata.getAnnotationAttributes(MqMessageListener.class.getCanonicalName())));

    }
}
